import React from 'react'
import { connect } from 'react-redux'

function ReduxDemo(props) {
  return (
    <div>
      <h2>{props.num}</h2>
      <button onClick={props.add}>累加</button>
    </div>
  )
}

const mapStateToProps = state => {
  return {
    num: state.num
  }
}

const mapDispatchToProps = dispatch => {
  return {
    add() {
      const actions = { type: 'add' }
      dispatch(actions)
    }
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(ReduxDemo)
